#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	for (int ll = 1; ll <= t; ll++)
	{
		string a;
		int n, i, j, k;
		cin >> a >> n;
		int len = a.size();
		for (k = 0; k < n; k++)
		{
			for (i = 0; i < len - 1; i++)
			{
				if (a[i] > a[i + 1])
				{
					for (j = i; j < len - 1; j++)
					{
						a[j] = a[j + 1];
					}
					break;
				}
			}
			len--;
		}
		i = 0;
		while (i <= len - 1 && a[i] == '0')
		{
			i++;
		}
		if (i == len)
		{
			cout << "0" << endl;
		}
		else
			for (j = i; j <= len - 1; j++)
			{
				cout << a[j];
			}
		cout<<endl;
	}
	return 0;
}
